package com;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class StudentMain {
	private static DatagramSocket ds; //接收教师机命令套接字
	private static Student student;
	public static void main(String[] args) {
		try {
			ds=new DatagramSocket(54528);
			new Thread(){
				public void run() {
					byte[] buf=new byte[1024];
					DatagramPacket dp=new DatagramPacket(buf, buf.length);
					while(true){
						try {
							ds.receive(dp);
							String message=new String(dp.getData(),0,dp.getLength());
							switch(message){
							case "start":
								student=new Student();
								Student.sendCmd("startReply", dp);
								break;
							case "stop":
								student.setScreenCast(false);
								student.dispose();
								student=null;
								System.gc();
								Student.sendCmd("stopReply", dp);
								break;
							case "file":break;
							}
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				};
			}.start();
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
